package com.example.xunai.dto.response.ai;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class StreamChatResponse {
    private String content;
    private String chunk;
    private Long conversationId;
    private String sessionId;
    private String modelType;
    private Integer tokenUsage;
    private LocalDateTime responseTime;
    private Boolean isStreaming;
    private String requestId;
    private String eventType; // "message", "complete", "error"

    public static StreamChatResponse message(String content, Long conversationId, String modelType) {
        return StreamChatResponse.builder()
                .content(content)
                .conversationId(conversationId)
                .modelType(modelType)
                .responseTime(LocalDateTime.now())
                .isStreaming(true)
                .eventType("message")
                .build();
    }

    public static StreamChatResponse complete(Long conversationId, String sessionId) {
        return StreamChatResponse.builder()
                .conversationId(conversationId)
                .sessionId(sessionId)
                .responseTime(LocalDateTime.now())
                .isStreaming(false)
                .eventType("complete")
                .build();
    }

    public static StreamChatResponse error(String error, String requestId) {
        return StreamChatResponse.builder()
                .content(error)
                .requestId(requestId)
                .responseTime(LocalDateTime.now())
                .eventType("error")
                .build();
    }

    public static StreamChatResponse chunk(String chunkContent, Long conversationId) {
        return StreamChatResponse.builder()
                .chunk(chunkContent)
                .conversationId(conversationId)
                .responseTime(LocalDateTime.now())
                .isStreaming(true)
                .eventType("chunk")
                .build();
    }
}